from django.conf import settings


import redis

'''
    string, list, hash, set, sortedset
'''

host = settings.REDIS['HOST']
port = settings.REDIS['PORT']
password = settings.REDIS['PASSWORD']

''' 操作单点 '''
pool = redis.ConnectionPool(host=host, port=port, decode_responses=True)
r = redis.Redis(connection_pool=pool, decode_responses=True)


def get_user_info(id):
    return r.hgetall(id)

def add_user_info(id, info):
    r.hmset(id, info)
    print('缓存成功')



''' 操作集群 '''

# from rediscluster import RedisCluster
#
# node = [{'host': '127.0.0.1', 'port': '6379'}]
# rc = RedisCluster(startup_nodes=node, decode_responses=True, password='xxx')  # password 视实际情况
# rc.set('name', 'dsc')
# print(rc.get('name'))